package Draw0506;

import javax.swing.*;
import java.awt.*;

public class DrawUIV1 {
    public void showUI(){
        JFrame jf = new JFrame();
        jf.setTitle("画图板V1.0");
        jf.setSize(800,700);
        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        jf.setLocationRelativeTo(null);
        jf.setLayout(new FlowLayout());
        JButton btn1 = new JButton("直线");
        JButton btn2 = new JButton("矩形");
        JButton btn3 = new JButton("等腰三角形");
        JButton btn4 = new JButton("圆形");
        JButton btn5 = new JButton("椭圆");
        JButton save = new JButton("保存");

        jf.add(btn1);
        jf.add(btn2);
        jf.add(btn3);
        jf.add(btn4);
        jf.add(btn5);
        jf.add(save);

        jf.setVisible(true);// 可视化

        DrawListenerV1 d1 = new DrawListenerV1();
        jf.addMouseListener(d1);

        //按钮添加动作监听器
        btn1.addActionListener(d1);
        btn2.addActionListener(d1);
        btn3.addActionListener(d1);
        btn4.addActionListener(d1);
        btn5.addActionListener(d1);
        save.addActionListener(d1);

        Graphics g = jf.getGraphics();

        d1.g = g;//传递画笔地址给监听器对象的属性g
        d1.jf = jf;

    }

    public static void main(String[] args){
        new DrawUIV1().showUI();
    }
}
